package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yinhe.system.domain.YhBaseinfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.service.IYhBaseinfoService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 基本信息Controller
 * 
 * @author yinhe
 * @date 2022-07-13
 */
@RestController
@RequestMapping("/system/baseinfo")
public class YhBaseinfoController extends BaseController
{
    @Autowired
    private IYhBaseinfoService yhBaseinfoService;

    /**
     * 查询基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhBaseinfo yhBaseinfo)
    {
        startPage();
        List<YhBaseinfo> list = yhBaseinfoService.selectYhBaseinfoList(yhBaseinfo);
        return getDataTable(list);
    }

    /**
     * 导出基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseinfo:export')")
    @Log(title = "基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhBaseinfo yhBaseinfo)
    {
        List<YhBaseinfo> list = yhBaseinfoService.selectYhBaseinfoList(yhBaseinfo);
        ExcelUtil<YhBaseinfo> util = new ExcelUtil<YhBaseinfo>(YhBaseinfo.class);
        util.exportExcel(response, list, "基本信息数据");
    }

    /**
     * 获取基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:baseinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhBaseinfoService.selectYhBaseinfoById(id));
    }

    /**
     * 新增基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:baseinfo:add')")
    @Log(title = "基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhBaseinfo yhBaseinfo)
    {
        return toAjax(yhBaseinfoService.insertYhBaseinfo(yhBaseinfo));
    }

    /**
     * 修改基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:baseinfo:edit')")
    @Log(title = "基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhBaseinfo yhBaseinfo)
    {
        return toAjax(yhBaseinfoService.updateYhBaseinfo(yhBaseinfo));
    }

    /**
     * 删除基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:baseinfo:remove')")
    @Log(title = "基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhBaseinfoService.deleteYhBaseinfoByIds(ids));
    }
}
